import { View } from '@tarojs/components';
import { AtButton } from 'taro-ui';
import './index.scss';

interface IProps {
  orderDetail: any;
  onRefound?: () => void;
  onCancel?: () => void;
  // 确认收货
  onConfirm?: () => void;
  onPay?: () => void;
}

export default function ({ orderDetail, onRefound, onCancel, onPay, onConfirm }: IProps) {
  const { orderStatus, payType, order_status } = orderDetail;
  if (orderStatus === 1) {
    return (
      <View className="order-button">
        <AtButton onClick={onCancel}>取消订单</AtButton>
        <AtButton type="primary" onClick={onPay}>
          去支付
        </AtButton>
      </View>
    );
  }
  if (orderStatus === 2 || orderStatus === 3) {
    // 已完成商品订单
    if (orderDetail.orderType === 1) {
      return (
        <View className="order-button">
          {payType === 2 && <AtButton onClick={onRefound}>申请退款</AtButton>}
          {orderStatus === 2 && order_status === 301 && (
            <AtButton type="primary" className="confirm-btn" onClick={onConfirm}>
              确认收货
            </AtButton>
          )}
        </View>
      );
    }
    // 线下支付，待服务
    if (orderStatus === 2 && payType === 1) {
      return null;
    } else {
      return (
        <View className="order-button">
          <AtButton onClick={onRefound}>申请退款</AtButton>
        </View>
      );
    }
  }
  return null;
}
